<?php

namespace App\Http\Controllers;


use App\Models\TradeRecommend;
use Illuminate\Http\Request;

class TradeController extends Controller
{
    public function index(Request $request)
    {
        $trade_recommends = TradeRecommend::select('id', 'product_id')
            ->with(['product' => function ($q) {
                $q->select('id', 'uuid', 'name', 'cover', 'summary', 'is_new');
                $q->with(['details' => function($query) {
                    $query->select('id', 'product_id', 'grade');
                }]);
            }])
            ->whereHas('product', function ($q) {
                $q->select('id', 'uuid')->where('auditing_status', 'online');
            })
            ->paginate(12);
        return view('en.trade')->with([
            'trade_recommends' => $trade_recommends
        ]);
    }
}